Phase-2 completion: post-process context types, m_riemann_solvers split, cleanup#1556
Conversation
There was a problem hiding this comment.
Pull request overview
Completes Phase 2 of the refactoring roadmap by (1) moving remaining post-process module state into context derived types, (2) splitting the large simulation Riemann solver module into smaller units while preserving the public surface, and (3) finishing the parameter-registry driven generation of Fortran declarations, case-opt declarations, and per-target MPI broadcast fragments (plus associated cleanup and a couple of latent bug fixes).
Changes:
- Add registry-driven generation for additional Fortran include fragments (
generated_case_opt_decls.fpp,generated_bcast.fpp) and extend typed derived-type namelist declarations viaTYPED_DECLS. - Introduce new shared Fortran module
m_global_parameters_commonand update build system/CMake to regenerate includes at build time. - Replace remaining literal enums with generated named constants across several simulation modules; add post-process
fd_context/output_contextand update post-process code to use them.
Reviewed changes
Copilot reviewed 53 out of 56 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| toolchain/mfc/params/generators/fortran_gen.py | Extend Fortran codegen to emit typed decls, case-opt decl blocks, and per-target MPI broadcast include fragments. |
| toolchain/mfc/params/generators/cmake_gen.py | Update generator script header comment to match build-time invocation. |
| toolchain/mfc/params/descriptions.py | Remove descriptions for deregistered derived-type members. |
| toolchain/mfc/params/definitions.py | Rename IB patch namelist bound constant; document/avoid dead registrations; add TYPED_DECLS. |
| toolchain/mfc/params_tests/test_fortran_gen.py | Add/adjust tests for typed decl emission, case-opt decl generation, and generated broadcast output. |
| toolchain/mfc/lint_docs.py | Derive allowed doc tokens from analytic intrinsics and registry constraints instead of a hardcoded skiplist. |
| toolchain/mfc/case_validator.py | Make recon_type validation message registry-driven (choices/names from CONSTRAINTS). |
| toolchain/mfc/build.py | Change build slug to a human-readable prefix plus existing 10-hex hash. |
| src/simulation/m_viscous.fpp | Replace reconstruction-type literals with generated named constants. |
| src/simulation/m_thinc.fpp | Replace interface-compression literal with named constant. |
| src/simulation/m_start_up.fpp | Use named recon-type constants; make Fypp loop literal order deterministic. |
| src/simulation/m_riemann_solver_hlld.fpp | New module for the HLLD solver extracted from the former monolith. |
| src/simulation/m_rhs.fpp | Use named constants for interface compression and reconstruction types. |
| src/simulation/m_qbmm.fpp | Use named constants for bubble-model choices. |
| src/simulation/m_muscl.fpp | Use named constants for MUSCL order/limiter choices. |
| src/simulation/m_mpi_proxy.fpp | Switch large portions of MPI broadcast logic to generated_bcast.fpp include; keep manual residue. |
| src/simulation/m_data_output.fpp | Use named constant for precision selection. |
| src/simulation/m_checker.fpp | Use named constants for recon type and MUSCL order checks. |
| src/simulation/m_cbc.fpp | Use named constants for recon type; make Fypp loop literal order deterministic. |
| src/simulation/m_bubbles.fpp | Use named constants for bubble-model choices. |
| src/simulation/m_bubbles_EL.fpp | Use named constant for precision selection in formatted output. |
| src/simulation/include/inline_riemann.fpp | Use named constants for average-state selection. |
| src/pre_process/m_start_up.fpp | Update IC state references to use the new ic_context bundle. |
| src/pre_process/m_mpi_proxy.fpp | Switch large portions of MPI broadcast logic to generated_bcast.fpp include; keep manual residue. |
| src/pre_process/m_initial_condition.fpp | Replace module-level IC state with type(ic_context) :: ic. |
| src/pre_process/m_data_output.fpp | Use named constant for precision selection. |
| src/pre_process/m_boundary_conditions.fpp | Remove stale/unused import. |
| src/post_process/m_start_up.fpp | Route FD coeff computation and output workspace through new contexts. |
| src/post_process/m_mpi_proxy.fpp | Switch large portions of MPI broadcast logic to generated_bcast.fpp include; keep manual residue; use named format constant. |
| src/post_process/m_derived_variables.fpp | Replace module-level FD work arrays with type(fd_context) :: fd and update allocation guards. |
| src/common/m_variables_conversion.fpp | Use named constant for average-state selection. |
| src/common/m_mpi_common.fpp | Use named constants for recon type and post-process format handling. |
| src/common/m_helper_basic.fpp | Use named constants for recon type when computing buffer size. |
| src/common/m_global_parameters_common.fpp | New shared global-parameters core and shared defaults/equation-index setup. |
| src/common/m_derived_types.fpp | Add ic_context, fd_context, and output_context derived types. |
| src/common/m_constants.fpp | Remove legacy recon-type constants and retain/clarify compile-time bounds constants. |
| docs/module_categories.json | Register new split modules in documentation categories. |
| docs/documentation/contributing.md | Update contributor guidance for build-time codegen and shared global parameters. |
| cmake/ParamsCodegen.cmake | New build-time codegen custom command/targets for generated .fpp includes. |
| cmake/MFCTargets.cmake | New target setup function and related configuration logic. |
| cmake/GPU.cmake | New consolidated GPU/compiler flags configuration. |
| cmake/Fypp.cmake | New consolidated Fypp preprocessing/HANDLE_SOURCES logic with generated-include dependencies. |
| .claude/rules/common-pitfalls.md | Update internal contributor/agent notes to reflect new shared global-params and codegen pipeline. |
| auto-generated at build time (ninja-tracked custom command) from the `TYPED_DECLS` and `FORTRAN_ARRAY_DIMS` | ||
| tables in `toolchain/mfc/params/definitions.py`. For a plain scalar registered with | ||
| `_r()` / `_nv()` above, no manual Fortran edit is needed — reconfigure (`./mfc.sh build`) | ||
| and the generated include in `m_global_parameters_common.fpp` (compiled per target) is updated | ||
| automatically. |
| After editing any generator or table, force regen by reconfiguring (`./mfc.sh build`) — | ||
| cached builds compile stale includes. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1556 +/- ##
==========================================
- Coverage 61.17% 60.94% -0.24%
==========================================
Files 74 82 +8
Lines 20313 19922 -391
Branches 2961 2924 -37
==========================================
- Hits 12427 12141 -286
+ Misses 5870 5805 -65
+ Partials 2016 1976 -40 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
fdfeed0 to
1d6969e
Compare
|
Both doc comments addressed — the passages predated the build-time generation command (added in #1552's build-hygiene work) and still described the configure-time era. Corrected text: a plain rebuild regenerates the includes automatically (the custom command is ninja-tracked against everything under |
Both passages predated the build-time generation command and still said reconfigure; a plain rebuild regenerates automatically (the command is ninja-tracked against toolchain/mfc/params/), and only adding a new file there needs a reconfigure. Flagged by Copilot review on MFlowCode#1556.
Both passages predated the build-time generation command and still said reconfigure; a plain rebuild regenerates automatically (the command is ninja-tracked against toolchain/mfc/params/), and only adding a new file there needs a reconfigure. Flagged by Copilot review on MFlowCode#1556.
Both passages predated the build-time generation command and still said reconfigure; a plain rebuild regenerates automatically (the command is ninja-tracked against toolchain/mfc/params/), and only adding a new file there needs a reconfigure. Flagged by Copilot review on MFlowCode#1556.
7bfe9c5 to
9717bee
Compare
Both passages predated the build-time generation command and still said reconfigure; a plain rebuild regenerates automatically (the command is ninja-tracked against toolchain/mfc/params/), and only adding a new file there needs a reconfigure. Flagged by Copilot review on MFlowCode#1556.
…ops, stale import
The allocation guards in s_initialize_derived_variables_module omitted qm_wrt while the s_compute_finite_difference_coefficients call guards in m_start_up include it, so a case writing only the Q-criterion accessed unallocated arrays. Pre-existing; found during fd_context review. Guards now mirror the call sites exactly.
…n_state NFC, pure motion. The four solver bodies call s_initialize/finalize_riemann_solver, s_populate_riemann_states_variables_buffers, and s_compute_viscous_source_flux, so keeping those in the dispatching core would create a use-cycle once the solvers move out. They go to the new lowest layer together with the 14 GPU_DECLARE'd state items they consume (declares move with declarations; lowest-consumer rule, bc_buffers precedent). Module-level allocation, GPU updates, and deallocation stay in core's s_initialize/finalize_riemann_solvers_module via use-association. Statement-multiset union vs the parent differs only by module boilerplate; GPU-directive census md5 unchanged; declare-target scoping verified for both files.
NFC, pure motion (calibration commit for the solver extractions). The solver body accesses flux_rsx_vf, flux_src_rsx_vf, is1/2/3 by host association and calls the per-sweep lifecycle helpers, both now use-associated from m_riemann_state. Core re-exports s_hlld_riemann_solver through its existing public list. Statement-multiset union vs the pre-split file differs only by module boilerplate; GPU-directive census md5 unchanged; declare-target scoping verified for all files.
NFC, pure motion. State access stays host-associated via m_riemann_state; the inline_riemann include moves with the solver since its macros expand here (roe_avg pulls in get_species_enthalpies_rt, gas_constant, molecular_weights, hence the m_thermochem only-list). Core re-exports the entry point through its existing public list. Statement-multiset union vs the pre-split file differs only by module boilerplate; GPU-directive census md5 unchanged; declare-target scoping verified for all files.
NFC, pure motion. State access stays host-associated via m_riemann_state; inline_riemann macros expand here (low-Mach correction), and the solver references molecular_weights directly, hence the m_thermochem only-list. Core re-exports the entry point through its existing public list. Statement-multiset union vs the pre-split file differs only by module boilerplate; GPU-directive census md5 unchanged; declare-target scoping verified for all files.
NFC, pure motion; completes the m_riemann_solvers split. State access stays host-associated via m_riemann_state; hllc additionally uses m_bubbles (f_cpbw_KM), m_bubbles_EE (rs/vs/ps), and m_surface_tension (s_compute_capillary_source_flux). With the last solver body gone, core drops the use-lists whose final consumers moved (m_variables_conversion, m_bubbles, m_bubbles_EE, m_surface_tension, m_chemistry, m_thermochem, the m_constants only-list) and the inline_riemann include; core keeps the dispatcher, module init/finalize, and the public re-exports. Statement-multiset union vs the pre-split file differs only by module boilerplate; GPU-directive census md5 unchanged; declare-target scoping verified for all six files.
Review follow-up: m_mpi_proxy and m_helper_basic are unreferenced in the slimmed core under all configs.
Both passages predated the build-time generation command and still said reconfigure; a plain rebuild regenerates automatically (the command is ninja-tracked against toolchain/mfc/params/), and only adding a new file there needs a reconfigure. Flagged by Copilot review on MFlowCode#1556.
9717bee to
adfea36
Compare
Both passages predated the build-time generation command and still said reconfigure; a plain rebuild regenerates automatically (the command is ninja-tracked against toolchain/mfc/params/), and only adding a new file there needs a reconfigure. Flagged by Copilot review on MFlowCode#1556.
… in the Riemann solvers On AMD flang OpenMP offload, the cross-translation-unit read of the static declare-target Re_size inside the Riemann solver kernels is unreliable and codegen-dependent: some solver kernels read it as 0, which collapses the interface Reynolds number to dflt_real and silently disables viscosity (the 2D_viscous_shock_tube regression from #1556). Making Re_size allocatable only moved the bug -- it fixed HLL/HLLC but broke the LF (riemann_solver=5) and IBM viscous paths (the inversion). Instead keep Re_size static and capture it into a host-set firstprivate local (Re_size_loc) in s_hll/hllc/lf_riemann_solver, so the kernels never read it from declare-target device memory and are immune to the compiler bug. Verified on Frontier AMD flang: 2D_viscous_shock_tube + 1D/2D LF-viscous + 2D IBM-viscous all pass. Underlying amdflang bug filed: ROCm/llvm-project#2890, llvm/llvm-project#203711.
…iemann split)
Summary
Context types (post_process). The remaining module-level state bundles follow the pilot pattern:
fd_context(finite-difference workspace:gm_rho_sf,fd_coeff_x/y/z) andoutput_context(the 18-member output workspace:q_sffamily, Silo extents/offsets, paths and handles). Strictly NFC, verified by emitted-Fortran equivalence after stripping the qualifier.m_riemann_solvers.fppsplit (4,706 lines → 6 modules). The four solvers extract tom_riemann_solver_{hll,hllc,hlld,lf}.fpp; the shared device state (14 GPU-declared arrays/bounds) and the per-sweep lifecycle + viscous helpers the solvers call land inm_riemann_state.fpp(the lowest layer — keeping them in the dispatching core would create a module cycle); the original module shrinks to a 116-line dispatcher that re-exports the public surface unchanged (zero external callers modified). Pure motion: statement-multiset equivalence under CPU/OpenACC/OpenMP emission; GPU-directive census identical (747 directives); everydeclare targetverified to live in its declaring module (the Cray ftn-1448 rule).Two latent bug fixes (found by review during the above):
qm_wrtis set, while the coefficient computation runs for it — unallocated access for Q-criterion-only cases. The allocation guards now mirror the call sites.patch_ibcounts above the namelist array bound — carried in Share the global-parameters core across executables; generate MPI broadcasts; build hygiene #1552's follow-ups; noted here because the registry-driven message change rides this stack.Cleanup batch: the
recon_typevalidator message now derives from the parameter registry (the last hardcoded vocabulary site); fypp#:forset-literals become list-literals (emission order was Python-hash-dependent across processes — builds are now order-reproducible); one stale import removed; the slimmed Riemann core drops two unused imports.Verification
Notes for reviewers
Gs_rs/Res_gsallocate without a finalize-side deallocate (base-identical), and the single-precisionq_sf_striple is never deallocated.m_riemann_stateholds the per-sweep helpers as well as state — the call graph forces it; the module doc enumerates the contents.Issues fixed
Fixes #1564 (Q-criterion-only post cases access unallocated FD coefficient arrays)
Tracked, not fixed here: #1568 and #1569 (deallocate gaps documented in the review notes above).